name: Django CI

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]
env:
  DJANGO_SECRET_KEY: qwerty*!(#*JJSAJ_!@+uiop123sdasd12124567890
  REDIS_CACHE_URL: localhost:6379/0
  DATABASES: |
      {
          "default": {
              "ENGINE": "django.db.backends.mysql",
              "NAME": "ecstasy",
              "USER": "root",
              "PASSWORD": "root_password",
              "HOST": "127.0.0.1",
              "PORT": "3306"
          }
      }

jobs:
  build:

    runs-on: ubuntu-latest
    services:
      database:
        image: mysql
        ports:
          - 3306:3306
        options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 5
        env:
          MYSQL_ROOT_PASSWORD: "root_password"
          MYSQL_USER: "user"
          MYSQL_PASSWORD: "password"
          MYSQL_DATABASE: "ecstasy"
      redis:
        image: redis
        ports:
          - 6379:6379

    strategy:
      max-parallel: 2
      matrix:
        python-version: ["3.10", "3.11"]

    steps:
    - uses: actions/checkout@v3
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v3
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        pip install coverage
    - name: Run Tests
      run: |
        coverage run manage.py test
    - name: Upload coverage reports to Codecov
      uses: codecov/codecov-action@v3
